package cn.monkey.chat.server.admin.domain.server;

import cn.monkey.chat.server.data.server.ServerLoad;
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
import org.redisson.api.RedissonClient;
import reactor.core.publisher.Mono;


public class RedisServerLoadRepository implements ServerLoadRepository {

    private final RMapCache<String, ServerLoad> mapCache;

    public RedisServerLoadRepository(RedissonClient redissonClient) {
        this.mapCache = redissonClient.getMapCache(ServerLoad.KEY);
    }

    @Override
    public Mono<ServerLoad> findById(String id) {
        RFuture<ServerLoad> future = this.mapCache.getAsync(id);
        return Mono.fromCompletionStage(future.toCompletableFuture());
    }
}
